scratch/Old text method.R

# Old asemic text method
#' create a grid of points
#'
#' @param x A vector for width
#' @param y A vector for Height
#' @importFrom ambient long_grid
setup_grid <- function(
  x,
  y
){
  ambient::long_grid(
    x,
    y
  )
}



#' Generate Asemic Text
#' @param lines The number of lines of text to generate
#' @param chars Number of chars per line
#' @param seed The random number seed
gen_text <- function(
  lines = 10,
  chars = 30,
  granularity = .1,
  seed = 42,
  height_lim = .5,
  width_lim = .5,
  use_spaces = TRUE

){
  grid <- setup_grid(seq(1,chars, granularity), 1:lines)
  grid$group <- grid$y

  num_rows <- nrow(grid)

  # Create noise for lines
  height_upper <-     height_lim
  set.seed(seed)
  up_or_down <- sample(c(-1, 0, 1), num_rows, replace = TRUE)

  set.seed(seed)
  change_h <- runif(num_rows, -1* height_lim, height_lim)
  set.seed(seed)
  change_w <- runif(num_rows, -1* width_lim,  width_lim )

  grid$y2 <- grid$y + change_h
  grid$x2 <- grid$x + change_w

  prob_sapce = .75*granularity



  if(use_spaces==TRUE){
    set.seed(seed)
    spaces <- sample(
      c(TRUE, FALSE),
      num_rows,
      TRUE,
      c(1-prob_sapce,prob_sapce
      )
    )

    print("Adding spaces")
    for (i in chars/2) {
      spaces <- ifelse(lag(spaces), spaces, FALSE)
      spaces <- ifelse(lead(spaces), spaces, FALSE)
    }


    grid$x2 <- ifelse(spaces, grid$x2, NA)

  }
  return(grid)

}

library(tidyverse)
data_init <- gen_text(lines = 70)

data_init$x_noise1 <- ambient::gen_perlin(data_init$x2, .01, seed = 42)
data_init$x_noise2 <- ambient::gen_perlin(data_init$x2, .005, seed = 42)
data_init$x_noise3 <- ambient::gen_perlin(data_init$x2, .0025, seed = 42)
data_init$x_noise4 <- ambient::gen_perlin(data_init$x2, .00125, seed = 42)



ggplot(data_init)+
  geom_path(aes(x2+x_noise4,y2, group = group), alpha =0.003125, size= 4  )+
  geom_path(aes(x2+x_noise3,y2, group = group), alpha =0.00625,  size= 3  )+
  geom_path(aes(x2+x_noise2,y2, group = group), alpha =.0125,    size= 2.5)+
  geom_path(aes(x2+x_noise1,y2, group = group), alpha =.125,     size= 2  )+
  geom_path(aes(x2,y2, group = group))+
  theme_canvas()
delabj/genArt documentation built on March 25, 2021, 11:56 p.m.